package com.hanwei.uap.common.data.crccalc;

import static java.lang.System.out;

/**
 * https://crccalc.com/
 * https://github.com/meetanthony/crcjava
 */
public class Main {

    public static void main(String[] args) {
        CrcCalculator calculator = new CrcCalculator(Crc16.Crc16CcittFalse);
        long result = calculator.Calc("abcdefgh".getBytes(), 0, 8);
        System.out.println(Long.toHexString(result).toUpperCase());
        check(Crc8.Params);

        check(Crc16.Params);

        check(Crc32.Params);

        check(Crc64.Params);
    }

    private static void check(AlgoParams[] params) {
        for (int i = 0; i < params.length; i++) {
            CrcCalculator calculator = new CrcCalculator(params[i]);
            long result = calculator.Calc(CrcCalculator.TestBytes, 0, CrcCalculator.TestBytes.length);
            if (result != calculator.Parameters.Check)
                out.println(calculator.Parameters.Name + " - BAD ALGO!!! " + Long.toHexString(result).toUpperCase());
        }
    }
}